package com.ggy.babybed.service;

import android.content.Intent;
import android.util.Log;

import com.ggy.babybed.network.NetWorkManager;
import com.ggy.babybed.wilddog.WildDogDataChange;
import com.ggy.babybed.wilddog.WildDogNode;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Collection;

/**
 * Created by sizi on 2016/5/19.
 */
public class ObserveNodeServiceImpl extends ObserveNodeService {

    private MessageNodeListener mMessageNodeListener;

    @Override
    public void onCreate() {
        super.onCreate();
        mMessageNodeListener=new MessageNodeListener();
        NetWorkManager.getNetWorkManager(this).addListenForNode(WildDogNode.MMS_NODE,mMessageNodeListener);
        Log.i(TAG,"service is on the runing!");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        flags = START_STICKY;
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void setMessageNode(boolean status) {
        NetWorkManager.getNetWorkManager(this).startListenNode(this,WildDogNode.MMS_NODE);
    }

    @Override
    public void setTempNode(boolean status) {
        NetWorkManager.getNetWorkManager(this).startListenNode(this, WildDogNode.WENDU_NODE);
        NetWorkManager.getNetWorkManager(this).startListenNode(this,WildDogNode.WENDU_HISTORY_NODE);
    }

    @Override
    public void setShiduNode(boolean status) {
        NetWorkManager.getNetWorkManager(this).startListenNode(this,WildDogNode.SHIDU_NODE);
        NetWorkManager.getNetWorkManager(this).startListenNode(this,WildDogNode.SHIDU_HISTORY_NODE);
    }


    @Override
    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        super.dump(fd, writer, args);
        writer.print("is in dumps");
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        NetWorkManager.getNetWorkManager(this).rmListenForNode(WildDogNode.MMS_NODE,mMessageNodeListener);
        mMessageNodeListener=null;
    }

    public class MessageNodeListener implements WildDogDataChange{
        @Override
        public void onchange(Collection data) {

        }
    }

    public class TempNodeListener implements WildDogDataChange{
        @Override
        public void onchange(Collection data) {

        }
    }

    public class ShiduNodeListener implements WildDogDataChange{
        @Override
        public void onchange(Collection data) {

        }
    }

    public class TempHistoryNode implements WildDogDataChange{
        @Override
        public void onchange(Collection data) {

        }
    }

    public class ShiduHistoryNode implements WildDogDataChange{
        @Override
        public void onchange(Collection data) {

        }
    }
}

